#include "hdobject.h"

HDObject::HDObject(QObject *parent)
: QObject(parent)
{
	_minH = 0.0f;
	_maxH = 360.0f;

	_minS = 0.0f;
	_maxS = 1.0f;

	_minV = 0.0f;
	_maxV = 1.0f;

	_searchRadius = 1.0f;
	texHueHist = 0;
	texSatHist = 0;
	texValHist = 0;
	texOffScreen = 0;

	bRangeHue = false;
	bRangeSat = false;
	bRangeVal = false;

	bCalcHueHist = false;
	bCalcSatHist = false;
	bCalcValHist = false;

	bAdaptiveHue = false;
	bAdaptiveSat = false;
	bAdaptiveVal = false;

	_pointsCount = 0;
	_centeroid.setX(0);
	_centeroid.setY(0);

	memset(hBins, 0, sizeof(hBins));
	memset(sBins, 0, sizeof(sBins));
	memset(vBins, 0, sizeof(vBins));

	_worldCoordinates.x=0;	
	_worldCoordinates.y=0;
	_worldCoordinates.z=0;
}

HDObject::~HDObject()
{

	glDeleteTextures(1, &texOffScreen);
	glDeleteTextures(1, &texHueHist);
	glDeleteTextures(1, &texSatHist);
	glDeleteTextures(1, &texValHist);
}


/************************************************************************/
/* Getters and Setters													*/
/************************************************************************/
float HDObject::searchRadius()
{
	return _searchRadius;
}

void HDObject::setSearchRadius(float radius)
{
	_searchRadius = radius;
}

QPointF HDObject::centroid()
{
	return _centeroid;
}

void HDObject::setCentroid(QPointF centeroid)
{
	_centeroid = centeroid;
}

int HDObject::pointsCount()
{
	return _pointsCount;
}
void HDObject::setPointsCount(int n)
{
	_pointsCount = n;
}

float HDObject::minHue()
{
	return _minH;
}

void HDObject::setMinHue(float minH, bool update /* = true */)
{
	_minH = minH;
	bCalcHueHist |= update;
}

float HDObject::maxHue()
{
	return _maxH;
}

void HDObject::setMaxHue(float maxH, bool update /* = true */)
{
	_maxH = maxH;
	bCalcHueHist |= update;
}

float HDObject::minSaturation()
{
	return _minS;
}

void HDObject::setMinSaturation(float minS, bool update /* = true */)
{
	_minS = minS;
	bCalcSatHist |= update;
}

float HDObject::maxSaturation()
{
	return _maxS;
}

void HDObject::setMaxSaturation(float maxS, bool update /* = true */)
{
	_maxS = maxS;
	bCalcSatHist |= update;
}

float HDObject::minValue()
{
	return _minV;
}

void HDObject::setMinValue(float minV, bool update /* = true */)
{
	_minV = minV;
	bCalcValHist |= update;
}

float HDObject::maxValue()
{
	return _maxV;
}

void HDObject::setMaxValue(float maxV, bool update /* = true */)
{
	_maxV = maxV;
	bCalcValHist |= update;
}

bool HDObject::rangeHue()
{
	return bRangeHue;
}

void HDObject::enableRangeHue(bool enable, bool update /* = true */)
{
	bRangeHue = enable;
	bCalcHueHist |= update;
}

bool HDObject::rangeSat()
{
	return bRangeSat;
}

void HDObject::enableRangeSat(bool enable, bool update /* = true */)
{
	bRangeSat = enable;
	bCalcSatHist |= update;
}

bool HDObject::rangeVal()
{
	return bRangeVal;
}

void HDObject::enableRangeVal(bool enable, bool update /* = true */)
{
	bRangeVal = enable;
	bCalcValHist |= update;
}

ThreeDimensionPoint* HDObject::worldCoordinates()
{
	return &_worldCoordinates;
}

void HDObject::setWorldCoordinates(float x, float y, float z)
{	
	_worldCoordinates.x = x;
	_worldCoordinates.y = y;
	_worldCoordinates.z = z;
}